{% extends 'courseset-manage/courseset-layout.html.twig' %}

{% block title %}
  {% if question|default(null) %}{{'course.question_manage.edit'|trans}}{% else %}{{'course.question_manage.manage'|trans}}{% endif %} - {{ parent() }}
{% endblock %}

{% set side_nav = 'question' %}
{% do script(['libs/es-ckeditor/ckeditor.js','libs/jquery-validation.js','app/js/question-manage/form/index.js']) %}

{% block main %}

{% set parentQuestion = parentQuestion|default(null) %}
{% set questionTypesDict = getQuestionTypes() %}

<div class="panel-col">
  <div class="courseset-manage-body__title">{{'course.question_manage'|trans}}</div>

    <ol class="breadcrumb">
      <li><a href="{{ path('course_set_manage_question',{id:courseSet.id}) }}">{{'course.question_manage'|trans}}</a></li>
      {% if parentQuestion %}
        <li><a href="{{ path('course_set_manage_question',{id:courseSet.id, parentId: parentQuestion.id}) }}">{{ questionTypesDict[parentQuestion.type] }}</a></li>
      {% endif %}
      <li>{% if question|default(null) %}{{'course.question_manage.edit'|trans}}{% else %}{{'course.question_manage.manage'|trans}}{% endif %} </li>
      <li class="active">{{ questionTypesDict[type] }}</li>
    </ol>

    <div id="question-creator-widget">
      <form id="question-create-form" data-role="question-form" class="form-horizontal quiz-question" method="post" action="{% if question|default(null) %}{{ path('course_set_manage_question_update',{courseSetId:courseSet.id, questionId:question.id, goto:request.query.get('goto')}) }}{% else %}{{ path('course_set_manage_question_create',{id:courseSet.id, type:type, parentId:parentQuestion.id|default(0), goto:app.request.get('goto')}) }}{% endif %}">

        {{ web_macro.flash_messages() }}

        {% if not parentQuestion %}
          <div class="form-group">
            <div class="col-md-2 control-label"><label>{{'course.question_manage.manage.belong'|trans}}</label></div>
            <div class="col-md-8 controls">
              <select class="form-control width-150" name="courseId" data-role="courseId" data-url="{{ path('course_set_manage_show_tasks',{courseSetId:courseSet.id})}}">
                <option value="0" {% if not question.courseId|default(0) %}selected{% endif %}>{{'course.question_manage.manage.default_belong'|trans}}</option>
                {% for course in courses if course %}
                  <option value="{{ course.id }}" {% if question.courseId|default(0) == course.id %}selected{% endif %}>{{ get_course_title(course) }}</option>
                {% endfor %}
              </select>
              <select class="form-control width-150" {% if not question.id|default(0) > 0 or not question.courseId|default(0) %}style="display:none;"{% endif %} name="lessonId" data-role="lessonId">
                <option value="0" {% if not question.lessonId|default(0) %}selected{% endif %}>{{'course.question_manage.manage.choose'|trans}}</option>
                {% for task in courseTasks|default([]) if task %}
                  <option value="{{ task.id }}" {% if question.lessonId|default(0) == task.id %}selected{% endif %}>{{ task.title }}</option>
                {% endfor %}
              </select>
            </div>
          </div>
        {% endif %}

        <div class="form-group">
          <div class="col-md-2 control-label"><label>{{'course.question_manage.manage.difficulty'|trans}}</label></div>
          <div class="col-md-8 controls radios">
            {{ radios('difficulty', {'simple':'course.question_manage.manage.easy_difficulty'|trans, 'normal':'course.question_manage.manage.normal_difficulty'|trans, 'difficulty':'course.question_manage.manage.hard_difficulty'|trans}, question.difficulty|default('normal')) }}
          </div>
        </div>

        <div class="form-group">
          <div class="col-md-2 control-label"><label for="question-stem-field" class="control-label-required">{{ question_stem_label|default('course.question_manage.manage.stem'|trans) }}</label></div>
          <div class="col-md-8 controls">
            <textarea class="form-control" id="question-stem-field" data-image-upload-url="{{ path('editor_upload', {token:upload_token('course')}) }}"  data-image-download-url="{{ path('editor_download', {token:upload_token('course')}) }}" name="stem" style="height:180px;">{{question.stem | default('')}}</textarea>
            {% set question_stem_help = question_stem_help|default('') %}
            {% if question_stem_help %}<div class="help-block">{{ question_stem_help|raw }}</div>{% endif %}
          </div>
        </div>

        {{ render(controller('AppBundle:File/Attachment:formFields',{targetType: 'question.stem', useType: true, targetId: question.id|default(0)},{ useType:true,})) }}
        
        {% block question_extra_fields %}{% endblock %}

        <div class="form-group">
          <div class="col-md-8 col-md-offset-2 controls ">
              <a href="javascript:;" data-toggle="collapse" data-role="advanced-collapse" data-target="#advanced-collapse" class="color-success collapsed">&raquo; {{'course.question_manage.manage.advanced_options'|trans}} ...</a>
          </div>
        </div>

        <div id="advanced-collapse" class="advanced-collapse collapse">
          <div class="form-group">
            <div class="col-md-2 control-label"><label for="question-analysis-field">{{'course.question_manage.manage.analysis'|trans}}</label></div>
            <div class="col-md-8 controls">
                <textarea class="form-control" id="question-analysis-field" data-image-upload-url="{{ path('editor_upload', {token:upload_token('course')}) }}" name="analysis" data-image-download-url="{{ path('editor_download', {token:upload_token('course')}) }}">{{ question.analysis|default('') }}</textarea>
            </div>
          </div>
           {{ render(controller('AppBundle:File/Attachment:formFields',{targetType: 'question.analysis', targetId: question.id|default(0)},{ useType:true,})) }}
          <div class="form-group">
            <div class="col-md-2 control-label"><label for="question-score-field">{{'course.question_manage.manage.score'|trans}}</label></div>
            <div class="col-md-8 controls">
              <input class="form-control width-input" value="{{question.score|default(2)}}" type="text" id="question-score-field" name="score" />
            </div>
          </div>
        </div>

        <div class="form-group">
          <div class="col-md-8 col-md-offset-2 controls">
            {% block question_buttons %}
              {% if not question|default(null) %}
                <button type="button" data-role="submit" class="cd-btn cd-btn-primary submit-btn" data-submission="continue" data-loading-text="{{'form.btn.save.submiting'|trans}}">{{'form.btn.save_and_continue_add'|trans}}</button>
              {% endif %}
              <button type="button" data-role="submit" class="cd-btn cd-btn-primary submit-btn" data-submission="submit" data-loading-text="{{'form.btn.save.submiting'|trans}}">{{'form.btn.save'|trans}}</button>
            {% endblock %}
            <a href="{{ path('course_set_manage_question', {id:courseSet.id, parentId:parentQuestion.id|default(0)}) }}" class="btn btn-link">{{'form.btn.return'|trans}}</a>
          </div>
        </div>

        <input type="hidden" name="submission">
        <input type="hidden" name="type" value="{{ type }}">
        <input type="hidden" name="parentId" value="{{ parentQuestion.id|default(0) }}">
        <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">

      </form>
    </div>

</div>


{% endblock %}
